package com.tan.steamship.controller;

import com.tan.steamship.common.Result;
import com.tan.steamship.mapper.CommentMapper;
import com.tan.steamship.service.CommentService;
import com.tan.steamship.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @author: longshifu
 * @time: 2023/5/31 21:33
 */
@RestController
public class CommentController {

    @Autowired
    CommentService commentService;
    @Autowired
    CommentMapper commentMapper;


    @Autowired
    UserService userService;

    @GetMapping("/comments/{routeId}")
    public Result comments(@PathVariable Integer routeId) {
        System.out.println(routeId);
        return Result.success("获取博客评论成功",commentService.getCommentsByBlogId(routeId));
    }

    /**
     * 新增评论
     *
     * @param para
     * @return
     */
    @PostMapping("/comments")
    public Result post(@RequestBody Map<String, Object> para) {
        System.out.println(para);
        return  Result.success( "评论发表成功", commentService.addComment(para));
    }


    @GetMapping("/comments/{id}/delete")
    public Result deleteComment(@PathVariable Long id) {
        commentMapper.deleteById(id);
        return Result.success("删除成功");
    }
}
